package channelService

import (
	"errors"
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedisRpc"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Hex"
	"time"
)

type executeService struct {
}

func (e *executeService) execute(recv2rspd map[string]string, recv2rsrd map[string]string, requestVO *commRedisRpc.ChannelRequestVO) (*commRedisRpc.ChannelRespondVO, error) {
	recv := Hex.EncodeToString(Hex.DecodeString(requestVO.Send))
	_, ok := recv2rspd[recv]
	if !ok {
		return nil, errors.New("没有对应的响应数据")
	}

	hexString := ""

	_, ok = recv2rsrd[recv]
	if ok && time.Now().UnixMilli()%2 == 0 {
		hexString = recv2rsrd[recv]
	} else {
		hexString = recv2rspd[recv]
	}

	respondVO := commRedisRpc.Type.ChannelRespondVO.Ok(requestVO)
	respondVO.Recv = hexString
	return respondVO, nil
}
